package cn.zwt.wolf.service.base.area;

import cn.zwt.wolf.domain.base.area.Area;
import cn.zwt.wolf.repository.base.area.AreaRepository;
import cn.zwt.wolf.util.JPQLSearchException;
import cn.zwt.wolf.util.SearchUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.NoResultException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zhangwt on 16-3-6.
 */
@Service
public class AreaService {
    @Autowired
    private AreaRepository areaRepository;
    @Autowired
    private SearchUtil searchUtil;
    private Logger logger = LoggerFactory.getLogger(AreaService.class);

    public Area findAreaByName(String name){
        Area area = null;
        if (name == null)
            return area;
        String hql = "from Area where status = 1 and name=:name";
        Map<String,Object> params= new HashMap<String, Object>();
        params.put("name",name);
        try {
            area = (Area) searchUtil.getSingleResult(hql, params);
        } catch (JPQLSearchException e) {
            logger.error("findAreaByName error :" + e.getMessage());
        }catch (NoResultException e){
            logger.error("findAreaByName error :" + e.getMessage());
        }
        return area;
    }
}
